package com.drzui.tickets.admin.entity;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.bigmouth.framework.util.result.DefaultResult;
import org.bigmouth.framework.util.result.Result;

import com.drzui.tickets.admin.AdminErrorCode;

public class Admin {
    private Integer id;

    private String username;

    private String loginname;

    private String password;
    
    private Integer usertype;

	private Date createtime = new Date();
    
    /**
	 * 验证方法
	 * 
	 * @return
	 */
	public Result validate() {
		Result result = new DefaultResult();
		if (StringUtils.isBlank(username)) {
			result.setErrorMessage(AdminErrorCode.USERSINFO_USERNAME_NOT);
			result.fail();
		} else if (StringUtils.length(username) > 32) {
			result.setErrorMessage(AdminErrorCode.USERSINFO_USERNAME_LEG_MAX);
			result.fail();
		}

		if (StringUtils.isBlank(loginname)) {
			result.setErrorMessage(AdminErrorCode.USERSINFO_LOGINNAME_NOT);
			result.fail();
		} else if (StringUtils.length(loginname) > 32) {
			result.setErrorMessage(AdminErrorCode.USERSINFO_LOGINNAME_LEG_MAX);
			result.fail();
		} else if (StringUtils.length(loginname) < 6) {
			result.setErrorMessage(AdminErrorCode.USERSINFO_LOGINNAME_LEG_MIN);
		}

		if (StringUtils.isBlank(password)) {
			result.setErrorMessage(AdminErrorCode.USERSINFO_PASSWORD_NOT);
			result.fail();
		} else if (StringUtils.length(password) > 32) {
			result.setErrorMessage(AdminErrorCode.USERSINFO_PASSWORD_LEG_MAX);
			result.fail();
		} else if (StringUtils.length(password) < 6) {
			result.setErrorMessage(AdminErrorCode.USERSINFO_PASSWORD_LEG_MIN);
		}

		return result;
	}

	public Result loginValidate() {
		Result result = new DefaultResult();
		
		if (StringUtils.isBlank(loginname)) {
			result.setErrorMessage(AdminErrorCode.USERSINFO_LOGINNAME_NOT);
			result.fail();
		}
		
		if (StringUtils.isBlank(password)) {
			result.setErrorMessage(AdminErrorCode.USERSINFO_PASSWORD_NOT);
			result.fail();
		}
		return result;
	}

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getLoginname() {
        return loginname;
    }

    public void setLoginname(String loginname) {
        this.loginname = loginname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    
    public Integer getUsertype() {
		return usertype;
	}

	public void setUsertype(Integer usertype) {
		this.usertype = usertype;
	}

    public Date getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }
}